import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/product_detail/controller/product_detail_controller.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/extension/widget_extension.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';

class ProductDetailPage extends BaseState<ProductDetailController> {
  final String heroTag;

  ProductDetailPage({required this.heroTag});

  @override
  ProductDetailController initController() => ProductDetailController();

  @override
  Widget initView(BuildContext context) {
    return Container(
      width: Get.width,
      height: Get.height,
      color: Colors.white,
      child: Stack(
        children: [
          SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Hero(
                  tag: heroTag,
                  child: SizedBox(
                    width: 720.width,
                    height: 720.height,
                    child: Swiper(
                      itemCount: 2,
                      autoplay: true,
                      itemBuilder: (BuildContext context, int index) {
                        return ImageCommon(
                          "/image/${controller.imagePre}_${index + 1}",
                        );
                      },
                    ),
                  ),
                ),
                Padding(
                  padding: MarginPaddingUtil.symmetric(horizontal: 32),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      35.heightBox,
                      TextCommon(
                        "${controller.productDetailBean?.price ?? "0.0"}",
                        color: Color(0xFFE04D4D),
                        size: 44.sp,
                        lineHeight: 64.sp,
                        fontWeight: FontWeight.bold,
                      ),
                      22.heightBox,
                      TextCommon(
                        controller.productDetailBean?.title ?? "",
                        size: 34.sp,
                        color: Color(0xFF414141),
                        lineHeight: 49.sp,
                        fontWeight: FontWeight.bold,
                      ),
                      22.heightBox,
                      TextCommon(
                        controller.productDetailBean?.description ?? "",
                        maxLines: 3,
                        color: Color(0xFF414141),
                        size: 24.sp,
                        lineHeight: 28.sp,
                      ),
                    ],
                  ),
                ),
                40.heightBox,
                ImageCommon("/image/${controller.imagePre}_detail"),
                121.heightBox,
              ],
            ),
          ),
          Positioned(
            bottom: 0,
            child: Container(
              width: Get.width,
              color: Colors.white,
              padding:
                  MarginPaddingUtil.symmetric(vertical: 22, horizontal: 200),
              child: Container(
                decoration: BoxDecoration(
                  color: Color(0xFFEDC88B),
                  borderRadius: BorderRadius.circular(50),
                ),
                width: 319.width,
                height: 80.height,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ImageCommon(
                      "/icon/buy_cart",
                      size: 38.sp,
                    ),
                    30.widthBox,
                    TextCommon(
                      "立即购买",
                      size: 32.sp,
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ],
                ),
              ),
            ).addClickEvent(() => controller.showSkuSelect()),
          ),
          Positioned(
            top: 77.height,
            left: 29.width,
            child: ImageAsset(
              "/icon/icon_detail_back",
              size: 60.sp,
            ).addClickEvent(() => Get.back()),
          ),
        ],
      ),
    );
  }
}
